package com.powernode.controller;


import com.powernode.common.Page;
import com.powernode.common.Result;
import com.powernode.domain.SysDictType;
import com.powernode.service.SysDictTypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/sysDictType")
public class SysDictTypeController extends BaseController{
    @Resource
    private SysDictTypeService sysDictTypeService;

    /**
     * 字典类型分页查询
     * @param page
     * @return
     */
    @PostMapping("/getByPage")
    public Result<Page<SysDictType>> getByPage(@RequestBody Page<SysDictType> page){
      page=sysDictTypeService.getByPage(page);
      return new Result<>(page);
    }
    /**
     * 添加字典类型
     * POST http://127.0.0.1:8080/sysDictType/save
     * 接口ID：60111921
     * 接口地址：https://www.apifox.cn/web/project/{{projectId}}/apis/api-{{id}}
     */
    @PostMapping("/save")
    public Result<?> save(@RequestBody SysDictType sysDictType){
        sysDictType.setCreateBy(getUsername());
        sysDictType.setCreateTime(new Date());
        sysDictTypeService.insert(sysDictType);
        return new Result("添加成功");
    }

    /**
     * 根据ID查询字典类型
     * GET http://127.0.0.1:8080/sysDictType/get/{dictId}
     * 接口ID：60111922
     * 接口地址：https://www.apifox.cn/web/project/{{projectId}}/apis/api-{{id}}
     */
    @GetMapping("/get/{dictId}")
    public Result<?> get(@PathVariable Long dictId){
        SysDictType sysDictType = sysDictTypeService.selectByPrimaryKey(dictId);
        return new Result<>(sysDictType);
    }

    /**
     * 修改字典类型
     * PUT http://127.0.0.1:8080/sysDictType/update
     * 接口ID：60111923
     * 接口地址：https://www.apifox.cn/web/project/{{projectId}}/apis/api-{{id}}
     */
    @PutMapping("/update")
    public Result<?> update(@RequestBody SysDictType sysDictType){
        sysDictType.setUpdateBy(getUsername());
        sysDictType.setUpdateTime(new Date());
        sysDictTypeService.updateByPrimaryKey(sysDictType);
        return new Result<>("修改成功");
    }

    /**
     * 删除字典类型
     * DELETE http://127.0.0.1:8080/sysDictType/delete/{dictId}
     * 接口ID：60111924
     * 接口地址：https://www.apifox.cn/web/project/{{projectId}}/apis/api-{{id}}
     */
    @DeleteMapping("/delete/{dictId}")
    public Result<?> delete(@PathVariable Long dictId){
        sysDictTypeService.deleteByPrimaryKey(dictId);
        return new Result<>("删除成功");
    }

    /**
     * 刷新缓存
     */
    @RequestMapping("/refreshCache")
    public Result<?> refreshCache(){
        sysDictTypeService.refreshCache();
        return new Result<>("刷新成功");
    }
}
